<template>
  <div>
    <my-breadcrumb :items="['消息管理', '反馈管理']"/>
    <search :formItems="searchItems" @search="getList" ref="search"/>
    <el-table :data="feedback" @sort-change="orderByTime">
      <el-table-column
        type="index"
        width="55">
      </el-table-column>
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        label="用户名称"
        prop="membername">
      </el-table-column>
      <el-table-column
        label="反馈时间"
        sortable="custom"
        prop="createtime">
      </el-table-column>
      <el-table-column
        label="反馈内容"
        prop="content">
      </el-table-column>
      <el-table-column
        label="是否处理"
        prop="status">
        <template slot-scope="scope">
          {{ scope.row.status === '0' ? '未处理' : '已处理' }}
        </template>
      </el-table-column>
      <el-table-column
        label="回复内容"
        prop="feedback">
      </el-table-column>
      <el-table-column
        label="操作"
        prop="id">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toBack(scope.row.id, scope.row.memberid)" v-if="scope.row.status === '0'">反馈</el-button>
          <el-button size="mini" type="text" v-else>已反馈</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNum"
        :page-sizes="[20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'feedback',
  data () {
    return {
      searchItems: [
        {
          label: '用户名称',
          type: 'input',
          key: 'membername'
        },
        {
          label: '反馈时间',
          type: 'times',
          key: 'times'
        },
        {
          label: '是否处理',
          type: 'select',
          key: 'status',
          options: [{id: '0', name: '未处理'}, {id: '1', name: '已处理'}]
        }
      ], // 检索结构
      feedback: [],
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0
      },
      lifting: '1'
    }
  },
  methods: {
    getList () {
      let searchData = {}
      if (this.$refs['search']) {
        searchData = this.$refs['search'].search()
      }
      let params = {...searchData, page: this.page.pageNum, size: this.page.pageSize, orderby: this.lifting}
      this.axios.get('/Complaint/index', {params})
        .then(res => {
          if (res.data.status) {
            this.page.total = Number(res.data.data.count)
            this.feedback = res.data.data.list
          }
        })
    },
    handleSizeChange (e) {
      this.page.pageSize = e
      this.getList()
    },
    handleCurrentChange (e) {
      this.page.pageNum = e
      this.getList()
    },

    toBack (id, mId) {
      this.$prompt('请输入回复内容', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        this.axios.post('/Complaint/addsend', this.qs.stringify({id, memberid: mId, feedback: value}))
          .then(res => {
            if (res.data.status === '1' || res.data.status === 1) {
              this.getList()
              this.$message.success('提交成功')
            }
          })
      })
    },

    orderByTime (lifting) {
      if (lifting.order === 'ascending') {
        this.lifting = '2'
      } else {
        this.lifting = '1'
      }
      this.getList()
    }
  },
  created () {
    this.getList()
  }
}
</script>

<style scoped>

</style>
